import axios from "./ajax";
// 火车票查询接口
// https://zhapp.4hl.cn/app/Address/huocar
// dtype: json
// start: 北京
// end: 石家庄
// date: 2018-09-04
function query_train(params,callback) {
  console.log(params)
  axios.post(
    "app/Address/huocar",
    "dtype=json"+
    "&start="+params.start.replace("市","")+
    "&end="+params.end.replace("市","")+
    "&date="+params.date
  ).then(res=>{
    if(res){
      callback(res);

    }
  }).catch(err=>{
    console.log(err);
    mui.toast("火车票查询接口出错了")
  })
}

/*
* 机票价格查询   query_air_price
* https://zhapp.4hl.cn/app/Address/feijiprice
* POST
*
* dtype: json
  orgCity: 北京
  dstCity: 武汉
  flightDate: 2018-09-06
  airline: ALL
  direct: true
  eticket: false
* */
function query_air_price(params, callback) {
  axios.post(
    "app/Address/feijiprice",
    "dtype=json"+
    "&orgCity="+params.start.replace("市","")+
    "&dstCity="+params.end.replace("市","")+
    "&flightDate="+params.date+
    "&airline=ALL"+
    "&direct=true"+
    "&eticket=false"
  ).then(res=>{
    if(res){
      callback(res.AVResult)
    }
  }).catch(err=>{
    console.log(err);
    mui.toast("机票价格查询接口出错了")
  })
}

/*
* 查询天气  query_weather
* https://zhapp.4hl.cn/app/Address/tianqi
* cityname: 123
  format: 2
  dtype: json
* */
function query_weather(params, callback) {
  axios.post(
    "app/Address/tianqi",
    "cityname="+params.cityname+
    "&format=2"+
    "&dtype=json"
  ).then(res=>{
    if(res){
      callback(res)
    }
  }).catch(err=>{
    console.log(err);
    mui.toast("查询天气接口出错了")
  })
}

// 机票价格查询   query_air_price
// 查询天气  query_weather
export default {
  query_train,
  query_air_price,
  query_weather
}
